package com.zhengjiang.annotation;

import java.lang.reflect.Method;
/**
 * @author zhengjiang
 * @version 1.0.0
 * @description
 * @date 2021/6/3
 **/
public class ProcessTest {
    public static void main(String[] args) {
        try {
            process("com.zhengjiang.annotation.MyTest");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void process(String clazz) throws ClassNotFoundException {
        int passed = 0;
        int failed = 0;
        Method[] methods = Class.forName(clazz).getMethods();
        for (Method m : methods){
            if (m.isAnnotationPresent(Testable.class)){
                try {
                    m.invoke(null);
                    passed ++;
                } catch (Exception e) {
                    System.out.println("方法" + m +"运行失败,异常:" + e.getCause());
                    failed ++;
                }
            }
        }
        System.out.println("annotaioned method total:" + (passed + failed) + " run success:"+passed + " failed:"+failed);

    }
}
